<template>
	<view>
		<my-search :bgcolor="bgcolor" @click='mjy'></my-search>
		<view class="scroll-view-container">
			<!-- 左 -->
			<scroll-view scroll-y="true" :style="{height: wh+'px'}" class='left-scroll-view'>
				<block v-for="(item,index) in catelist" :key='index'>
					<view :class="['left-scroll-view-item',active== index ? 'active':'']" @click="addChange(index)">
						{{item.cat_name}}
					</view>
				</block>
			</scroll-view>
			<!-- 右 -->
			<scroll-view scroll-y="true" :style="{height: wh+'px'}" class='right-scroll-view' :scroll-top="scrollTop">
				<view class="cate-2" v-for="(item2,index) in catelist2" :key='index'>
					<view class="cate-2-title">/
						{{item2.cat_name}}/
					</view>
					<view class="cate-3-list">
						<view class="cate-3-item" v-for="(item3,index3) in item2.children" :key="index3"
							@click="goGoodsList(item3)">
							<image src="../../static/0.1.jpg" mode=""></image>
							<text>{{item3.cat_name}}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import {
		categoriesdata
	} from '../../api/cate_request.js'
	export default {
		data() {
			return {
				wh: 0,
				catelist: [],
				active: 0,
				catelist2: [],
				scrollTop: 0,
				bgcolor:'pink'
				}
		},
		methods: {
			mjy(){
				console.log('mjy')
			},
			async getcategories() {
				const {
					data: res
				} = await categoriesdata();
				console.log(res)
				if (res.meta.status !== 200) return uni.$showMsg();
				this.catelist = res.message;
				this.catelist2 = res.message[0].children
			},
			addChange(index) {
				this.active = index;
				this.catelist2 = this.catelist[index].children;
				this.scrollTop = this.scrollTop === 0 ? 1 : 0;
			},
			goGoodsList(item3) {
				uni.navigateTo({
					url: '/ok/goods_list/goods_list?catId=' + item3.cat_id
				})
			}

		},
		onLoad() {
			const add = uni.getSystemInfoSync();
			this.wh = add.windowHeight -50;
			this.getcategories();
		}
	}
</script>

<style lang="scss">
	.scroll-view-container {
		display: flex;

		.left-scroll-view {
			width: 240rpx;

			.left-scroll-view-item {
				line-height: 120rpx;
				font-size: 15px;
				color: pink;
				background-color: gray;
				text-align: center;

				&.active {
					background-color: white;
					position: relative;

					&::before {
						content: '';
						display: block;
						width: 6rpx;
						height: 60rpx;
						background-color: red;
						position: absolute;
						left: 0;
						top: 50%;
						transform: translateY(-50%);
					}
				}
			}
		}

		.right-scroll-view {
			.cate-2 {
				.cate-2-title {
					font-size: 20px;
					font-weight: 500;
					text-align: center;
					padding: 15px 0;
				}

				.cate-3-list {
					font-size: 15px;
					display: flex;
					flex-wrap: wrap;

					.cate-3-item {
						width: 33.33%;
						display: flex;
						flex-direction: column;
						align-items: center;

						image {
							width: 60px;
							height: 90px;
						}
					}
				}
			}
		}
	}
</style>
